<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" href="/css/logicss/common.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/print.css" rel="stylesheet" media = "print"/>
<link type="text/css" href="/css/logicss/utils.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/e24m.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/dark.css" rel="stylesheet" />
<style type="text/css" media="screen">
        @import '/css/logicss/utils.css';
        @import '/css/logicss/mix.css';
        @import '/css/logicss/small.css';
        @import '/css/logicss/e24m.css';
        @import '/css/logicss/dark.css';
        @import '/css/logicss/common.css';
        #nav-site { margin-top: 1.75em; }
    </style>
<script type="text/javascript">

var obj = null;
function ab()
{
	var label = document.getElementById(obj);
	var str = document.getElementById("string");
	label.innerText = str.value;
	obj = null;
}

function edit(id)
{ 
	if(obj!=id)
	{ 
		if(obj!=null)
		{ab();}
		obj = id;
		var lable = document.getElementById(id);
		var l = lable.innerText;
		lable.innerHTML = "<input type='text' id='string' onblur='ab()'></input>";
		var str = document.getElementById("string");
		str.focus();
		str.value=l;
	}
}

function add()
{
	var form = document.getElementById("fortifierData");
	form.name.value = document.getElementById("1").innerText;
	form.unit.value = document.getElementById("2").innerText;
	form.discription.value = document.getElementById("3").innerText;
	form.operation.value = 1;
	form.submit();
}

function save()
{
	if(obj!=null)
	{ab();}
	var form = document.getElementById("resetData");
	form.name.value = document.getElementById("1").value;
	form.unit.value = document.getElementById("2").value;
	form.decription.value = document.getElementById("3").innerText;


	//if(!(isDigit(form.max.value)&&isDigit(form.min.value)&&form.max.value>form.min.value))
	//{
	//	alert("输入数据错误，请重新出入");
	//	return;
	//}
	
	alert("修改成功");
	form.submit();
}


function erase()
{
	var form = document.getElementById("deleteDate");
	form.submit();
}


function checkForm()
{
	return true;
}


</script>
<title>Untitled Document</title>
</head>
<body id="page-home" style="background: url(/images/bg.jpg);">
<div id="contanier" class="content grid">
<div>
<div id="section" class="first col w5">
<img id = "logo" alt='logo' src='/images/logos/logo_small.jpg' width=80 height=40/>
</div>
<div id ="content-head" class="last col w6" >
<ol class="h-list" style="margin-top:18px">
<li><a href="#" onclick="add()">添加</a></li>
<li><a href="#" onclick="save()">保存</a></li>
<li><a href="#" onclick="erase()">删除</a></li>
</ol>
</div>
</div>
<hr/>

</div>

<div id ="content-main" class="content grid" >
<div class="first col w5">
<ol class="v-list" style="text-align:left;">
<li><a >名称：</a></li>
<li><a >常用单位：</a></li>
<li><a >描述：</a></li>
</ol>
</div>


<form method="post" id="fortifierData" onsubmit="return checkForm()">
	<input type="hidden" name="name" />
	<input type="hidden" name="unit" />
	<input type="hidden" name="operation" />
</form>

<div class="last col w5">
<ol class="v-list" style="text-align:left;">
<%@ page import="java.util.List" %>
<%@ page import="db.nutriment.Nutriment" %>
<%@ taglib uri="/WEB-INF/tld/list-taglib.tld" prefix="tj" %>
<% 

String id = (String)request.getAttribute("id");
String nutriment = (String)request.getAttribute("name");
String cl = (String)request.getAttribute("unit");
String des = (String)request.getAttribute("description");
@SuppressWarnings("unchecked")
List<Nutriment> nutriments = (List<Nutriment>)request.getAttribute("nutriments");
%>

<li><tj:list id='1' list='${nutriments}' defaultId = '<%=id %>'></tj:list></li>
<%
out.print("<li><a id='2' onclick='edit(this.id)' href='#'>"+cl+"</a></li>");
out.print("<li><a id='5' onclick='edit(this.id)' href='#'>"+des+"</a></li>");
%>
</ol></div>
<form method = "post" id = "deleteDate" action="/nutriment/removeNutriment.do">
<%
out.print("<input type='hidden' name='id' value= '"+id+"' /> "); 
%>
</form>


<form method = "post" id ="resetData" action = "/nutriment/resetnutriment.do">
<%
     out.print("<input type='hidden' name='id' value= '"+id+"' /> "); 
%>
<input type = 'hidden' name='name'/>
<input type = 'hidden' name='unit'/>
<input type = 'hidden' name='description'/>
</form>

</div>
</body>
</html>